package com.smart.wap.app;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.manager.member.entities.models.MemberMaterialPig;
import com.smart.manager.member.entities.views.MemberView;
import com.smart.manager.product.entities.models.PigGoods;
import com.smart.manager.product.entities.models.PropsServe;
import com.smart.manager.product.entities.models.PropsSnacks;
import com.smart.utils.MemberAcl;
import com.smart.utils.MemberStp;
import com.smart.wap.bodys.ShopBody;
import com.smart.wap.bodys.ShopResult;
import com.smart.wap.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author Admin
 * @date 2023/10/05
 */
@Api(tags = "WTB-移动端-玩家商店")
@RestController
@RequestMapping(SmartConstant.WAP_API_PREFIX + "app/shop")
@RequiredArgsConstructor
@Log4j2
public class ShopController {

    private final ShopService shopService;


    @ApiOperation(value = "获取邀请注册活动详情")
    @GetMapping(value = "getActivity")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<MemberView> > getActivity() {
        Long memberId = MemberAcl.getLoginId();
        List<MemberView> activity = shopService.getActivity(memberId);
        return AjaxResult.data(activity);
    }

    @ApiOperation(value = "获取售卖中的猪仔")
    @GetMapping(value = "getGoodsList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PigGoods>> getGoodsList() {
        Long memberId = MemberAcl.getLoginId();
        List<PigGoods> result = shopService.getGoodsList(memberId);
        return AjaxResult.data(result);
    }

    @ApiOperation(value = "获取兑换中的零食")
    @GetMapping(value = "getSnacksList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PropsSnacks>> getSnacksList() {
        Long memberId = MemberAcl.getLoginId();
        List<PropsSnacks> snacksList = shopService.getSnacksList(memberId);
        return AjaxResult.data(snacksList);
    }

    @ApiOperation(value = "获取售卖中的套餐")
    @GetMapping(value = "getAllComboList")
//    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<ShopResult.Combo> getAllList() {
//        Long memberId = MemberAcl.getLoginId();
        ShopResult.Combo allList = shopService.getAllList(false);
        return AjaxResult.data(allList);
    }

    @ApiOperation(value = "获取售卖中的套餐")
    @GetMapping(value = "getAllComboList/{isOrganic}")
//    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<ShopResult.Combo> getAllList(@PathVariable Boolean isOrganic) {
//        Long memberId = MemberAcl.getLoginId();
        ShopResult.Combo allList = shopService.getAllList(isOrganic);
        return AjaxResult.data(allList);
    }


    @ApiOperation(value = "获取售卖中的服务")
    @GetMapping(value = "getAllServeList")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<List<PropsServe>> getServeList() {
        Long memberId = MemberAcl.getLoginId();
        List<PropsServe> result = shopService.getServeList(memberId);
        return AjaxResult.data(result);
    }


    @ApiOperation(value = "购买/赠送猪猪")
    @PostMapping(value = "getBuyPig")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<MemberMaterialPig> getBuyPig(@RequestBody @Validated ShopBody.EditBody body) {
        Long memberId = MemberAcl.getLoginId();
        MemberMaterialPig memberMaterialPig = shopService.buyPig(memberId, body);
        return AjaxResult.data(memberMaterialPig);
    }

//    @ApiOperation(value = "验证兑换卷")
//    @PostMapping(value = "verifyExchange")
//    @SaCheckLogin(type = MemberStp.TYPE)
//    public AjaxResult<ShopResult.Rem> exchangePig(@RequestBody @Validated ShopBody.ExchangeBody body) {
//        Long memberId = MemberAcl.getLoginId();
//        ShopResult.Rem rem = shopService.verifyExchange(body,memberId);
//        return AjaxResult.data(rem);
//    }
//


    @ApiOperation(value = "兑换零食")
    @PostMapping(value = "redeemSnacks")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Map<String, Object>> redeemSnacks(@RequestBody @Validated ShopBody.GoodsBody body) {
        Long memberId = MemberAcl.getLoginId();
        Map<String, Object> objectMap = shopService.redeemSnacks(memberId, body);
        return AjaxResult.data(objectMap);
    }


    @ApiOperation(value = "购买服务")
    @PostMapping(value = "purchaseServices")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<String> purchaseServices(@RequestBody @Validated ShopBody.ServeBody body) {
        Long memberId = MemberAcl.getLoginId();
        String string = shopService.purchaseServices(memberId, body);
        return AjaxResult.data(string);
    }
    @ApiOperation(value = "给猪购买套餐")
    @PostMapping(value = "getPutBuyGoods")
    @SaCheckLogin(type = MemberStp.TYPE)
    public AjaxResult<Map<String, Object>> getPutBuyGoods(@RequestBody @Validated ShopBody.GoodsPigBody body) {
        Long memberId = MemberAcl.getLoginId();
        Map<String, Object> map = shopService.buyPutPig(memberId, body);
        return AjaxResult.data(map);
    }

}
